package com.gsit.expenditure.client.domina;

import java.util.Date;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import com.gsit.expenditure.domain.Bill;
import com.gsit.expenditure.domain.CustomerAddress;
import com.gsit.expenditure.domain.OtherBill;
import com.gsit.expenditure.domain.TravelBill;
import com.gsit.expenditure.utils.BillType;

public class BillBean implements BeanHendler<Bill> {
	

	private LongProperty serialNumber = new SimpleLongProperty();
	private ObjectProperty<Date> billDate = new SimpleObjectProperty<Date>();
	private StringProperty referenceNumber = new SimpleStringProperty("");
	private StringProperty particulars = new SimpleStringProperty("");
	private StringProperty description = new SimpleStringProperty("");
	private ObjectProperty<BillType> billType = new SimpleObjectProperty<BillType>();
	private ObjectProperty<Date> createdDate = new SimpleObjectProperty<Date>();
	private DoubleProperty rate = new SimpleDoubleProperty();
	private IntegerProperty days = new SimpleIntegerProperty();
	private DoubleProperty distance = new SimpleDoubleProperty();
	private StringProperty address1 = new SimpleStringProperty("");
	private StringProperty vehicleNumber = new SimpleStringProperty("");
	private StringProperty city = new SimpleStringProperty("");
	private StringProperty state = new SimpleStringProperty("");
	private StringProperty pinCode = new SimpleStringProperty("");
	private StringProperty customer = new SimpleStringProperty("");
	private DoubleProperty amount = new SimpleDoubleProperty();
	private DoubleProperty totalAmount = new SimpleDoubleProperty();
	
	private Boolean select = new Boolean(false);
	private Bill bill;
	public BillBean(Bill bill) {
		if (bill == null) {
			bill = new Bill();
		}
		this.bill = bill;
		init(bill);
	}

	
	@Override
	public Bill getObject() {
		
		TravelBill travelBill=new TravelBill(); 
		OtherBill obill=new OtherBill();
		CustomerAddress address=new CustomerAddress();
		if(this.bill == null){
			this.bill = new Bill();
		}
		bill.setCreatedDate(createdDate.getValue());
		System.out.println("CreatedDate>>>>>>>>>"+createdDate.getValue());
		bill.setReferenceNumber(referenceNumber.getValue());
		//bill.setBillDate(billDate.getSelectedDate());
		bill.setAmount(amount.getValue());
		obill.setDescription(description.getValue());
		travelBill.setParticulars(particulars.getValue());
		travelBill.setRate(rate.getValue());
		
		
		return this.bill;
	}
	
	
	@Override
	public void init(Bill bill) {
		
		if (bill instanceof TravelBill) {
			TravelBill travelBill = (TravelBill) bill;
			serialNumber.setValue(travelBill.getId());
			referenceNumber.setValue(bill.getReferenceNumber());
			amount.setValue(travelBill.getAmount());
			billDate.setValue(travelBill.getBillDate());
			billType.set(BillType.TRAVEL);
			particulars.setValue(travelBill.getParticulars());
			createdDate.setValue(bill.getCreatedDate());
			rate.setValue(travelBill.getRate());
			days.setValue(travelBill.getDays());
			distance.setValue(travelBill.getDistance());
			address1.setValue(bill.getCustomer().getAddress().getAddress1());
			state.setValue(bill.getCustomer().getAddress().getState());
			city.setValue(bill.getCustomer().getAddress().getCity());
			pinCode.setValue(bill.getCustomer().getAddress().getPinCode());
			//vehicleNumber.setValue(bill.getVehicle().getVehicleNumber());
			customer.setValue(bill.getCustomer().getFullName());
			
		}else if (bill instanceof OtherBill) {
			OtherBill otherBill = (OtherBill) bill;
			serialNumber.setValue(otherBill.getId());
			referenceNumber.setValue(otherBill.getReferenceNumber());
			amount.setValue(otherBill.getAmount());
			billDate.setValue(otherBill.getBillDate());
			billType.set(BillType.OTHER);
		    description.setValue(otherBill.getDescription());
		    createdDate.setValue(bill.getCreatedDate());
		   	
		}
		
	
	}
	
	
	
	
	
	
	public String getCustomer() {
		return customer.get();
	}


	public void setCustomer(String customer) {
		this.customer.set(customer);
	}


	public String getCity() {
		return city.get();
	}


	public void setCity(String city) {
		this.city.set(city);
	}


	public String getState() {
		return state.get();
	}


	public void setState(String state) {
		this.state.set(state);
	}


	public String getPinCode() {
		return pinCode.get();
	}


	public void setPinCode(String pinCode) {
		this.pinCode.set(pinCode);
	}


	public String getAddress1() {
		return address1.get();
	}


	public void setAddress1(String address1) {
		this.address1.set(address1);
	}


	public String getVehicleNumber() {
		return vehicleNumber.get();
	}


	public void setVehicleNumber(String vehicleNumber) {
		this.vehicleNumber.set(vehicleNumber);
	}


	public Double getDistance() {
		return distance.get();
	}


	public void setDistance(Double distance) {
		this.distance.set(distance);
	}


	public Integer getDays() {
		return days.get();
	}


	public void setDays(Integer days) {
		this.days.set(days);
	}


	public Double getRate() {
		return rate.get();
	}


	public void setRate(Double rate) {
		this.rate.set(rate);
	}


	public Date getCreatedDate() {
		return createdDate.get();
	}


	public void setCreatedDate(Date createdDate) {
		this.createdDate.set(createdDate);
	}


	public Date getBillDate() {
		return billDate.get();
	}


	public void setBillDate(Date billDate) {
		this.billDate.set(billDate);
	}


	public String getParticulars() {
		return particulars.get();
	}


	public void setParticulars(String particulars) {
		this.particulars.set(particulars);
	}


	public String getReferenceNumber() {
		return referenceNumber.get();
	}


	public void setReferenceNumber(String referenceNumber) {
		this.referenceNumber.set(referenceNumber);
	}


	public Double getAmount() {
		return amount.get();
	}


	public void setAmount(Double amount) {
		this.amount.set(amount);
	}


	public String getDescription() {
		return description.get();
	}


	public void setDescription(String description) {
		this.description.set(description) ;
	}


	public Boolean getSelect() {
		return select;
	}


	public void setSelect(Boolean select) {
		this.select = select;
	}


	public Bill getBill() {
			
		return bill;
	}


	public void setBill(Bill bill) {
		this.bill = bill;
	}


	public void setSerialNumber(LongProperty serialNumber) {
		this.serialNumber = serialNumber;
	}


	public Long getSerialNumber() {
		return serialNumber.get();
	}

	public void setSerialNumber(Long serialNumber) {
		this.serialNumber.set(serialNumber);
	}

	@Override
	public void reLoad(Bill bill) {
		this.bill=bill;
		init(bill);
		
	}


	@Override
	public void clean() {
		
	}


		
}
